import 'package:flutter/material.dart';

class PopupMenuButtonDemo extends StatefulWidget {
  const PopupMenuButtonDemo({super.key});

  @override
  State<PopupMenuButtonDemo> createState() => _PopupMenuButtonDemoState();
}

class _PopupMenuButtonDemoState extends State<PopupMenuButtonDemo> {
  String _currentMenuItem = 'Home';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('PopupMenuButtonDemo'),
        elevation: 0,
      ),
      body: Container(
        padding: const EdgeInsets.all(6),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                PopupMenuButton(
                  initialValue: _currentMenuItem,
                  tooltip: _currentMenuItem,
                  icon: const Icon(Icons.arrow_drop_down_circle),
                  onSelected: (value) {
                    debugPrint(value);
                    setState(() {
                      _currentMenuItem = value;
                    });
                  },
                  itemBuilder: (context) {
                    const List<PopupMenuItem<String>> items = [
                      PopupMenuItem<String>(
                        value: 'Home',
                        child: Text('Home'),
                      ),
                      PopupMenuItem<String>(
                        value: 'Admin',
                        child: Text('Admin'),
                      ),
                      PopupMenuItem<String>(
                        value: 'About',
                        child: Text('About'),
                      ),
                    ];
                    return items;
                  },
                ),
                Text(_currentMenuItem),
              ],
            )
          ],
        ),
      ),
    );
  }
}
